/**
 * creation: 15-may-08
 */

package org.jfonia.connect;

import org.jfonia.connect.arithmetic.IntMinimum;
import org.jfonia.connect.logic.IfElse;
import org.jfonia.connect.logic.IntLessThan;
import org.jfonia.structure.Slice;

/**
 * 
 * @author wijnand.schepens@gmail.com
 *
 */
public class ParallelIteration {
	
	public static Node createParallelProceeder(Slice slice1, String id1, Slice slice2, String id2)
	{
		Value<Integer> tl1 = slice1.getLookaheadKey(id1);
		Value<Integer> tl2 = slice2.getLookaheadKey(id2);
		Value<Integer> tl = new Cache<Integer>(new IntMinimum(tl1, tl2));
		
		Node fw1 = slice1.getFastForwarder(id1, tl);
		Node fw2 = slice2.getFastForwarder(id2, tl);
		
		Node proc12 = new BasicNode();
		proc12.addCallTarget(fw1);
		proc12.addCallTarget(fw2);
		proc12.addCallTarget(tl);	// update cache AFTER forwarding !!
		
		return new IfElse(new IntLessThan(tl, new SimpleValue<Integer>(Integer.MAX_VALUE)),
				          proc12);
	}
}
